enum MessageType {
  text,
  emoji,
  image,
  video,
  error, // 如果你服务端也定义了 error 类型·
}

class SendMessagePayload {
  final String content;
  final String? roomId;
  final String? toImId;
  final MessageType messageType;

  SendMessagePayload({
    required this.content,
    this.roomId,
    this.toImId,
    required this.messageType,
  });

  Map<String, dynamic> toJson() => {
    'content': content,
    'roomId': roomId,
    if (toImId != null) 'toIm_Id': toImId,
    'messageType': messageType.name,
  };

  factory SendMessagePayload.fromJson(Map<String, dynamic> json) {
    return SendMessagePayload(
      content: json['content'],
      roomId: json['roomId'],
      toImId: json['toIm_Id'],
      messageType: MessageType.values.firstWhere(
            (e) => e.name == json['messageType'],
        orElse: () => MessageType.text, // 默认值防崩溃
      ),
    );
  }
}
